from app.database.connector import Database
from app.database.dao import BaseDAO

class UserDAO(BaseDAO):
    def __init__(self):
        super().__init__('users')
    
    def get_user_by_username(self, username):
        """根据用户名查询用户"""
        query = f"SELECT * FROM {self.table_name} WHERE username = %s"
        result = Database().execute_query(query, (username,))
        return result[0] if result else None
    
    def get_user_by_id(self, user_id):
        """根据用户ID查询用户"""
        return self.find_by_id(user_id)
    
    def get_user_list(self, page=1, page_size=10, conditions=None):
        """获取用户列表
        Args:
            page: 页码
            page_size: 每页记录数
            conditions: 查询条件
        """
        offset = (page - 1) * page_size
        return self.find_all(limit=page_size, offset=offset, conditions=conditions)
    
    def create_user(self, user_data):
        """创建新用户"""
        return self.create(user_data)
    
    def update_user(self, user_id, user_data):
        """更新用户信息"""
        return self.update(user_id, user_data)
    
    def delete_user(self, user_id):
        """删除用户"""
        return self.delete(user_id)